package com.hins.component.hlock.model;

import com.hins.component.hlock.handler.HlockTimeoutException;
import com.hins.component.hlock.handler.release.ReleaseTimeoutHandler;

/**
 * 释放锁超时执行的策略
 *
 * @author Leslie
 * @date 2021/9/7 10:35
 */
public enum ReleaseTimeoutStrategy implements ReleaseTimeoutHandler {

    /**
     * 继续执行业务逻辑，不做任何处理
     */
    NO_OPERATION() {
        @Override
        public void handle(LockInfo lockInfo) {
            // do nothing
        }
    },
    /**
     * 快速失败
     */
    FAIL_FAST() {
        @Override
        public void handle(LockInfo lockInfo) {

            String errorMsg = String.format("Found Lock(%s) already been released while com.hins.component.hlock.lock lease time is %d s", lockInfo.getName(), lockInfo.getLeaseTime());
            throw new HlockTimeoutException(errorMsg);
        }
    }
}
